﻿@model cloudscribe.Core.Web.ViewModels.SiteSettings.SiteBasicSettingsViewModel
@using cloudscribe.Core.Models
@using cloudscribe.Web.Common.Models
@using cloudscribe.Web.Common.Components
@using cloudscribe.Web.Common.Extensions
@using cloudscribe.Core.Web
@using Microsoft.Extensions.Options
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<CloudscribeCore> sr
@inject ICkeditorOptionsResolver editorOptionsResolver
@inject IOptions<MultiTenantOptions> multiTenantOptionsAccessor

@{
    MultiTenantOptions multiTenantOptions = multiTenantOptionsAccessor.Value;
    bool useFolderTenants = true;
    if (multiTenantOptions.Mode != MultiTenantMode.FolderName) { useFolderTenants = false; }
    bool useHostTenants = true;
    if (multiTenantOptions.Mode != MultiTenantMode.HostName) { useHostTenants = false; }
    var ckOptions = await editorOptionsResolver.GetCkeditorOptions();
    var baseUrl = this.Context.Request.GetCurrentBaseUrl() + "/";
}
<form method="post" class="form-horizontal" role="form" asp-antiforgery="true" data-submit-once="true">
    <div asp-validation-summary="All" class="text-danger"></div>
    <input asp-for="SiteId" type="hidden" />
    <input asp-for="ReturnPageNumber" type="hidden" />
    <div class="form-group">
        <label asp-for="SiteName" class="col-md-2 control-label">@sr["Site Name"]</label>
        <div class="col-md-10">
            <input asp-for="SiteName" class="form-control" />
            <span asp-validation-for="SiteName" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <label asp-for="AliasId" class="col-md-2 control-label">@sr["AliasId"]</label>
        <div class="col-md-10">
            <span class="form-control">@Model.AliasId</span>
            <span asp-validation-for="AliasId" class="text-danger"></span>
        </div>
    </div>
    @if (useFolderTenants)
    {
        <div class="form-group">
            <label asp-for="SiteFolderName" class="col-md-2 control-label">@sr["Site Folder Name"]</label>
            <div class="col-md-10">
                <div class="input-group">
                    <span class="input-group-addon">@baseUrl</span>
                    <input asp-for="SiteFolderName" class="form-control"
                           data-remote-validate-onblur="true"
                           data-error-target-id="spnFolderNameWarn"
                           data-additional-input-ids="SiteId"
                           data-validation-url='@Url.Action("FolderNameAvailable", "SiteAdmin")' />
                </div>
                <span id="spnFolderNameWarn" class="text-danger" data-error-message='@sr["Requested Site Folder Name is not available, please try another value"]'></span>
                <span asp-validation-for="SiteFolderName" class="text-danger"></span>
                @Html.ValidationMessage("foldererror", new { @class = "text-danger" })
            </div>
        </div>
    }
    else if (useHostTenants)
    {
        <div class="form-group">
            <label asp-for="HostName" class="col-md-2 control-label">@sr["Host Name"]</label>
            <div class="col-md-10">
                <input asp-for="HostName" class="form-control" />
                <span asp-validation-for="HostName" class="text-danger"></span>
                @Html.ValidationMessage("hosterror", new { @class = "text-danger" })
                <a class="hostmap" asp-action="SiteHostMappings"
                   asp-controller="SiteAdmin"
                   asp-route-siteGuid="SiteGuid"
                   asp-route-slp="ReturnPageNumber">@sr["Domain Mappings"]</a>
            </div>
        </div>
    }
    <div class="form-group">
        <label asp-for="TimeZoneId" class="col-md-2 control-label">@sr["Time Zone"]</label>
        <div class="col-md-10">
            <select asp-for="TimeZoneId"
                    asp-items="Model.AllTimeZones" class="form-control"></select>
            <span asp-validation-for="TimeZoneId" class="text-danger"></span>
        </div>
    </div>
    @if (Model.AvailableThemes.Count > 0)
    {
        <div class="form-group">
            <label asp-for="Theme" class="col-md-2 control-label">@sr["Theme"]</label>
            <div class="col-md-10">
                <select id="Layout" asp-for="Theme"
                        asp-items="Model.AvailableThemes" class="form-control"></select>
                <span asp-validation-for="Theme" class="text-danger"></span>
            </div>
        </div>
    }
    @if (Model.AvailableCultures.Count > 0)
    {
        <div class="form-group">
            <label asp-for="ForcedCulture" class="col-md-2 control-label">@sr["Forced Culture"]</label>
            <div class="col-md-10">
                <select asp-for="ForcedCulture"
                        asp-items="Model.AvailableCultures" class="form-control"></select>
                <span asp-validation-for="ForcedCulture" class="text-danger"></span>
            </div>
        </div>
    }
    @if (Model.AvailableUICultures.Count > 0)
    {
        <div class="form-group">
            <label asp-for="ForcedUICulture" class="col-md-2 control-label">@sr["Forced UI Culture"]</label>
            <div class="col-md-10">
                <select asp-for="ForcedUICulture"
                        asp-items="Model.AvailableUICultures" class="form-control"></select>
                <span asp-validation-for="ForcedUICulture" class="text-danger"></span>
            </div>
        </div>
    }
    <div class="form-group">
        <label asp-for="GoogleAnalyticsProfileId" class="col-md-2 control-label">@sr["Google Analytics Tracking Id"]</label>
        <div class="col-md-10">
            <input asp-for="GoogleAnalyticsProfileId" class="form-control" />
            <span asp-validation-for="GoogleAnalyticsProfileId" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <label asp-for="AddThisProfileId" class="col-md-2 control-label">@sr["AddThis.com ProfileId"]</label>
        <div class="col-md-10">
            <input asp-for="AddThisProfileId" class="form-control" />
            <span asp-validation-for="AddThisProfileId" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <div class="checkbox">
                <label>
                    <input asp-for="IsClosed" /> @sr["Close Site To Public"]
                </label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label asp-for="ClosedMessage" class="col-md-2 control-label">@sr["Closed Message"]</label>
        <div class="col-md-10">
            <textarea class="form-control" rows="5" asp-for="ClosedMessage"
                      data-ckeditor-unobtrusive=""
                      data-ckeditor-config-url="@ckOptions.CustomConfigPath"
                      data-ckeditor-config-language="@ckOptions.LanguageCode"
                      data-ckeditor-config-dropfileuploadurl="@ckOptions.DropFileUrl"
                      data-ckeditor-config-filebrowserurl="@ckOptions.FileBrowseUrl"
                      data-ckeditor-config-imagebrowseurl="@ckOptions.ImageBrowseUrl"></textarea>
            <span asp-validation-for="ClosedMessage" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <button id="btnSave" name="submit" type="submit" class="btn btn-default" data-disabled-text='@sr["Working..."]' data-enabled-text='@sr["Save"]'>@sr["Save"]</button>
            @if ((Model.ShowDelete) && (Model.SiteId != Guid.Empty))
            {
                <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#confirmDeleteModal">
                    @sr["Delete"]
                </button>
                @Html.ValidationMessage("deleteerror", new { @class = "text-danger" })
            }
        </div>
    </div>
</form>
@if ((Model.ShowDelete) && (Model.SiteId != Guid.Empty))
{
    <form id="deleteform" class="form-inline" asp-controller="SiteAdmin"
          asp-action="SiteDelete">
        <input asp-for="SiteId" type="hidden" />
        <input asp-for="ReturnPageNumber" type="hidden" />
        <div class="modal fade" id="confirmDeleteModal" tabindex="-1" role="dialog" aria-labelledby="confirmDeleteHeading">
            <div class="modal-dialog modal-sm" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label='@sr["Close"]'><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="confirmDeleteHeading">@sr["Confirm Delete"]</h4>
                    </div>
                    <div class="modal-body">
                        @string.Format(sr["Are you sure you want to delete the site {0} and all related data? You cannot undo this action."], Model.SiteName)
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">@sr["Cancel"]</button>
                        <input type="submit" value='@sr["Delete"]' class="btn btn-danger btn-ok" />
                    </div>
                </div>
            </div>
        </div>
    </form>
}
